<?php
if (!defined('__COLA_DIR__')) exit;

/**
 * Home 组件
 *
 * @author edikud
 * @package Widget
 * @copyright Copyright (c) 2019 Cola (http://www.mcooo.com)
 * @license GNU General Public License 2.0
 */
class Widget_Ucenter_Home extends Widget
{
    public $map;

    /**
     * 执行函数
     *
     * @access public
     * @return void
     */
    public function execute()
    {
		if(!$this->user->hasLogin()) {
			throw new Widget_Exception(_t('请求的地址不存在'), 404);
		}
    }
	
    public function indexList()
    {
		$this->user->pass('contributor', true) && $arrlist['start'] = array(
		    _t('点击下面的链接快速开始'),
			array(
			    array('&raquo;', '<a href="'.$this->options->ucenterUrl('post', false).'">'._t('撰写新文章').'</a>'),
				array('&raquo;', '<a href="'.$this->options->ucenterUrl('page', false).'">'._t('创建新页面').'</a>'),
		    )
		);

		$this->user->pass('admin', true) && $arrlist['start'][1][] = array('&raquo;', '<a href="'.$this->options->ucenterUrl('options-general', false).'">'._t('系统设置').'</a>');

		$arrlist['userInfo'] = array(
		    _t('我的信息'),
			array(
			    array(_t('登录帐号'), $this->user->name .' ['.$this->user->groups[0][$this->user->group] .']'),
				array(_t('内容条数'), $this->user->contentsNum),
				array(_t('评论条数'), $this->user->commentsNum),
				array(_t('最后活动时间'), (new Date($this->user->activated))->format('Y-m-d \TH:i:s')),
				array(_t('上次登录'), (new Date($this->user->logged))->format('Y-m-d \TH:i:s')),
				array(_t('注册时间'), (new Date($this->user->created))->format('Y-m-d \TH:i:s')),
		    )
		);
		
		$os = $this->widget('Widget_OS');
		$this->user->pass('admin', true) && $arrlist['osInfo'] = array(
		    _t('服务器配置'),
			array(
			    array(_t('操作系统'), $os->OS),
				array(_t('环境软件'), $this->request->getServer('SERVER_SOFTWARE')),
				array(_t('PHP'), PHP_VERSION),
				array(_t('上传限制'), $os->uploadMaxFilesize),
				array(_t('执行限制'), $os->maxExecutionTime . ' s'),
				array(_t('安全模式'), $os->safeMode),
				array(_t('远程访问'), $os->allowUrlFopen),
		    )
		);
		
		$stat = $this->widget('Widget_Stat');
		$arrlist['generalInfo'] = array(
		    _t('综合统计'),
			array(
			    //array(_t('分类总数'), $stat->categoriesNum),
				array(_t('文章内容'), $stat->myPostsNum),
				//array(_t('附件数目'), $stat->attachsNum),
				//array(_t('用户数目'), $stat->usersNum),
				array(_t('评论数目'), $stat->myCommentsNum),
		    )
		);
		
		$this->user->pass('admin', true) && $arrlist['systemInfo'] = array(
		    _t('系统信息'),
			array(
			    array(_t('程序版本'), 'Cola '.$this->options->version),
				array(_t('程序设计'), '<a href="http://mcooo.com" target="_blank">edikud</a>'),
				array(_t('界面设计'), '<a href="http://mcooo.com" target="_blank">edikud</a>'),
				array(_t('特别感谢'), '<a href="http://www.typecho.org" target="_blank" title="Typecho team">Typecho team</a> <a href="http://www.xiuno.com" target="_blank" title="Xiuno BBS创始人">老黄@xiuno</a> <a href="http://www.wangeditor.com/" target="_blank" title="COLA内置wangEditor编辑器">wangEditor</a>'),
		    )
		);
		
		/** 插件接口 */
		//HOOK $arrlist | PLUG_Ucenter_Home($arrlist, $this);

		if(null !== $this->map){
			return call_user_func($this->map, $arrlist, $this);
		}

		$html = '';
        foreach ($arrlist as $key=> $value) {
			$Layout = new Layout();
			list($title, $columns) = $value;
			$Layout->prepend('<h3>'.$title.'</h3>');
		    foreach ($columns as $column) {
			    list($name, $word) = $column;
			    $Layout->lists(array(
				    '<small class="text-muted">'.$name.'</small>',
					$word,
				));
		    }
			$html .= $Layout->render();
        }

		return $html;	
    }

}
